View Javadoc
1 package jrre.instructionset.objects; 2 3 import jrre.*; 4 import jrre.types.*; 5 import jrre.classloader.classfile.pool_entries.*; 6 7 public class PutField extends jrre.instructionset.Instruction { 8 9 private int operandOne; 10 private int operandTwo; 11 12 public PutField(int operandOne, int operandTwo){ 13 14 this.operandOne = operandOne; 15 this.operandTwo = operandTwo; 16 17 name = "putfield "+operandOne+" "+operandTwo; 18 description = "pushes a field."; 19 length = 2; 20 } 21 22 /*** 23 * Executes the <strong><code>putfield</code></strong> instruction. 24 * @task Add cases where the value to put is two bytes. 25 */ 26 public void execute(){ 27 28 jrre.api.java.lang.Class thisClass = Stack.getClassContainingMethod(); 29 30 int fieldIndex = (operandOne << 8 | operandTwo); 31 32 CPFieldRef fieldRef = (CPFieldRef)thisClass.getSymbol(fieldIndex); 33 CPNameType nameType = (CPNameType)thisClass.getSymbol(fieldRef.getNameTypeIndex()); 34 35 String fieldType = ((CPUTF8)thisClass.getSymbol(nameType.getDescriptorIndex())).getValue(); 36 //System.out.println("fieldType "+fieldType); 37 38 Type valueToPut = Stack.popOperand(); 39 40 // Will need ||'s 41 if(fieldType.equals("J")){ 42 PrimitiveType valueToPutTwo = (PrimitiveType)Stack.popOperand(); 43 44 ((PrimitiveType)valueToPut).setValue( (((PrimitiveType)valueToPut).getValue() << 8 | valueToPutTwo.getValue()) ); 45 } 46 47 //ReferenceType referenceToPutInto = (ReferenceType)Stack.popOperand(); 48 Type referenceToPutInto = Stack.popOperand(); 49 50 //System.out.println("\n\n"+referenceToPutInto); 51 52 ObjectInstance objectToPutInto = ((ReferenceType)referenceToPutInto).getValue(); 53 objectToPutInto.setInstanceValue(fieldIndex, valueToPut); 54 } 55 56 public String toString(){ 57 StringBuffer toReturn = new StringBuffer(); 58 toReturn.append("putfield "); 59 toReturn.append(Integer.toHexString(operandOne)); 60 toReturn.append(" "); 61 toReturn.append(Integer.toHexString(operandTwo)); 62 return toReturn.toString(); 63 } 64 }

This page was automatically generated by Maven